<?php
/**
 * 微博后台管理项目 媒体表数据层

 */
define("CACHE_MBLOG_COUNT_RT_TOP","mblog_reply_");
class db_mblog_reply extends db_base
{
	var $table_name  ="mblog_reply";
	
	
	function get_item_by_id($id)
	{
		$id = intval($id);
		$where = "id = $id ";
		$content = $this->get_alllist($this->table_name,1,1,"",$where);
		return $content[0];
	}
	
	function get_list_by_ids($ids)
	{
		if(is_array($ids))
		{
			$ids = join(",",$ids);
		}
		
		$ids = mysql_escape_string($ids);
		$where = " id in ( {$ids} )";
		$content = $this->get_alllist($this->table_name,"","","", $where);
		return $content;
	}
	
	
	function get_list_by_mid($mid,$p,$pcount)
	{
		$mid = intval($mid);
		$p = intval($p);
		$pcount = intval($pcount);
		
		
		$where = "mid = $mid and status = 1";
		$content = $this->get_alllist($this->table_name,$p,$pcount,"id desc ",$where);
		return $content;
	}
	
	function get_count_by_mid($mid)
	{
		$mid = intval($mid);
		
		$where = "mid = $mid and status = 1";
		$content = $this->get_listcount($this->table_name,$where);
		return $content;
	}
	
	function update_mblog_reply_info_by_id($id,$status="")
	{
		$id = intval($id);
		
		$where = "id = $id";
		$ary = array();

		if(strlen($status)>0)$ary["status"] = $status;
		
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
	}
	
	
	function insert_mblog_reply_info($uid,$user_nickname,$mid,$content,$head_url)
	{
		// 插入数据
		$ary = array();

		$ary["head_url"] = $head_url;
		$ary["create_nickname"] = $user_nickname;
		$ary["mid"] = $mid;
		$ary["content"] = $content;
		
		$ary["create_uid"] = $uid;
		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["status"] = 1;
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	
	
	
	
	function cron_insert_mblog_reply_info($uid,$user_nickname,$mid,$content,$sina_id,$head_url,$time)
	{
		// 插入数据
		$ary = array();

		
		$ary["create_nickname"] = $user_nickname;
		$ary["mid"] = $mid;
		$ary["content"] = $content;
		$ary["sina_id"] = $sina_id;
		$ary["create_uid"] = $uid;
		$ary["create_time"] = $time;
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["status"] = 1;
		$ary["head_url"] = $head_url;
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	
	function cron_get_count_by_sina_id($sina_id)
	{
		$where = "sina_id = $sina_id";
		
		$count =$this->get_listcount($this->table_name,$where);
	
		return $count;
	}
	
	function cron_get_count_by_mid($mid)
	{
		$where = "mid = $mid and status = 1";
		
		$count =$this->get_listcount($this->table_name,$where);
	
		return $count;
	}
	
}
